let HENMJGame = require("../game_server/majiang/henmj_game");


let mj = new HENMJGame({roomId:1});
mj._handCardsMap[0] = {32:3};
mj._combo[0] = [];
mj._hua = [];
mj._hua[0] = [34,35,38];
mj._pos = [27,29];

HENMJGame.prototype.calScore = function(chairId, zimo, huCard){
    let cp = Object.assign({}, this._handCardsMap[chairId]);
    if (!zimo) {
        cp[huCard]++;
    }
    let chong = {
        info: [],
        value: 1
    }
    //红中、发财、自风位刻子一冲
    this._combo[chairId].forEach(combo => {
        if (['angang', 'penggang', 'gang', 'peng'].includes(combo.type)) {
            if (combo.card == 31) {
                chong.info.push("红中刻子1冲");
                chong.value += 1;
            } else if (combo.card == 32) {
                chong.info.push("发财刻子1冲");
                chong.value += 1;
            } else if (combo.card == this._pos[chairId]) {
                chong.info.push("自风位刻子1冲");
                chong.value += 1;
            }
        }
    });
    if (cp[31] >= 3) {
        chong.info.push("红中刻子1冲");
        chong.value += 1;
    }
    if (cp[32] >= 3) {
        chong.info.push("发财刻子1冲");
        chong.value += 1;
    }
    if (cp[this._pos[chairId]] >= 3) {
        chong.info.push("自风位刻子1冲");
        chong.value += 1;
    }

    //混一色4冲
    let se = [0, 0, 0, 0];
    for (let item in cp) {
        item = Number(item);
        if (item >= 27) {
            se[3] = 1;
        } else {
            se[item % 9] = 1;
        }
    }

    this._combo[chairId].forEach(item => {
        if (item.card >= 27) {
            se[3] = 1;
        } else {
            se[item.card % 9] = 1;
        }
    })
    if (se.filter(item => item == 1).length == 2 && se[3] == 1) {
        chong.info.push("混一色4冲");
        chong.value += 4;
    }

    //清一色、3个财神或4个财神8冲
    if (se.filter(item => item == 1).length == 1) {
        chong.info.push("清一色8冲");
        chong.value += 8;
    }
    if (cp[this._magic] == 3) {
        chong.info.push("3个财神8冲");
        chong.value += 8;
    }
    if (cp[this._magic] == 4) {
        chong.info.push("4个财神8冲");
        chong.value += 8;
    }

    //1个花1冲
    // this._hua[chairId].forEach(item => {
    //     item -= 34;
    //     chong.info.push("春夏秋冬梅兰竹菊".split('')[item] + '1冲');
    //     chong.value += 1;
    // });

    //春夏秋冬、梅兰竹菊加任意一个1冲的 = 8冲
    if (
        //至少5个花
        (
            this._hua[chairId].length > 4 &&
            (
                this._hua[chairId].filter(item => item <= 37).length >= 4 ||
                this._hua[chairId].filter(item => item >= 38).length >= 4
            )
        ) ||
        (
            //至少4个花
            this._hua[chairId].length >= 4 &&
            (
                this._hua[chairId].filter(item => item <= 37).length >= 4 ||
                this._hua[chairId].filter(item => item >= 38).length >= 4
            ) &&
            chong.info.find(item => item.indexOf("刻子"))
        )
    ) {
        chong.info.push("超级8冲");
        chong.value += 8;
    }

    //自风位花1冲
    let pos = this._pos[chairId] - 27;
    if (
        this._hua[chairId].includes(34 + pos) ||
        this._hua[chairId].includes(38 + pos)
    ) {
        chong.info.push("自风位花1冲")
        chong.value += 1;
    }

    //8冲封顶
    if (chong.value > 4) {
        chong.value = 4;
    }

    return chong;
}


console.log(mj.calScore(0,true,1));